package com.yuecai.modules.yc_order;


import com.yuecai.modules.yc_order.service.dto.YcOrderQueryCriteria;
import com.yuecai.modules.yc_order.service.impl.YcOrderService;
import com.yuecai.modules.yc_receiver_info.service.YcReceiverInfoService;
import com.yuecai.modules.yc_receiver_info.service.dto.YcReceiverInfoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/order")
public class OrderController {


    @Autowired
    private YcOrderService ycOrderService;

    @GetMapping
    public ResponseEntity<Object> query(YcOrderQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(ycOrderService.queryAll(criteria,pageable), HttpStatus.OK);
    }


    /**
     * 订单详情
     * @param orderSn
     * @return
     */
    @GetMapping("/details/{orderSn}")
    public ResponseEntity<Object> goods(@PathVariable String orderSn) throws Exception {

        return ycOrderService.findOrderGoodsByOrderSn(orderSn);
    }


    /**
     * 发货
     * @return
     */
    @PutMapping("/delivery/{orderSn}/{distributionId}")
    public ResponseEntity<Object> takeDelivery(@PathVariable String orderSn,@PathVariable Long distributionId) throws Exception {
        return ycOrderService.takeDelivery(orderSn,distributionId);
    }


    /**
     * 打印信息
     * @param orderNos
     * @return
     */
    @PostMapping("/print")
    public ResponseEntity<Object> print(@RequestBody String[] orderNos){
        return new ResponseEntity<>(ycOrderService.print(orderNos), HttpStatus.OK);
    }

}